/**
 * 
 */
$(function(){
	webUtils.nameSpace("wiseMen.oa.examSubject");
	
	wiseMen.oa.examSubject.add=function(grid,bt,gridDef){
		var EXAMID=gridDef.params.queryDatas.EXAMID;
		if(EXAMID && EXAMID!=-1){
			var uuid=webUtils.uuid();
			var d=webUtils.dialog({
				url:ctx+"/dataModelDefAct/editTpl.do?dms=OA_EXAM_SUBJECT&OA_EXAM_SUBJECT_EXAMID="+EXAMID+"&winId="+uuid,
				onremove:function(){
					r.remove();
					webUtils.topicPublish("dialog.close."+uuid,{uuid:uuid});
				}
			});
			var r=webUtils.topicSubscribe("dialog.submit.success."+uuid,function(data){
				grid.bootstrapTable("refresh");
				d.close();
			});
		}else{
			webUtils.error("请选择具体的考试");
		}
	}
	
	wiseMen.oa.examSubject.view=function(grid,rowIndex){
		var row = grid.bootstrapTable("getRowByIndex", rowIndex);
		var uuid=webUtils.uuid();
		if(row.CONTENTTYPE==2){
			window.open(row.LINK);
		}else{
			var d=webUtils.dialog({
				url:ctx+"/dataModelDefAct/viewTpl.do?dms=OA_EXAM_SUBJECT&OA_EXAM_SUBJECT_ID="+row.ID+"&winId="+uuid,
				onremove:function(){
				}
			});
		}
	}
	wiseMen.oa.examSubject.mod=function(grid,rowIndex){
		var row = grid.bootstrapTable("getRowByIndex", rowIndex);
		var uuid=webUtils.uuid();
		var d=webUtils.dialog({
			url:ctx+"/dataModelDefAct/editTpl.do?dms=OA_EXAM_SUBJECT&OA_EXAM_SUBJECT_ID="+row.ID+"&winId="+uuid,
			onremove:function(){
				r.remove();
				webUtils.topicPublish("dialog.close."+uuid,{uuid:uuid});
			}
		});
		var r=webUtils.topicSubscribe("dialog.submit.success."+uuid,function(data){
			grid.bootstrapTable("refresh");
			d.close();
		});
	}
	wiseMen.oa.examSubject.del=function(grid,rowIndex){
		var row = grid.bootstrapTable("getRowByIndex", rowIndex);
		webUtils.confirm("删除数据将不可恢复，是否继续！",function(r){
			if(r){
				$.post(ctx + "/formDataAction/delByIds.do", {tableName:"OA_EXAM_SUBJECT",ids: row.ID}, function (data) {
	                if (data.success) {
	                	grid.bootstrapTable("refresh");
	                } else {
	                	webUtils.error(data.msg);
	                }
	            }, 'json');
			}
		});
	}
	
	wiseMen.oa.examSubject.setUp=function(grid,rowIndex){
		var row = grid.bootstrapTable("getRowByIndex", rowIndex);
		$.post(ctx+"/formDataAction/setSort.action",
				{code:"OA_EXAM_SUBJECT",id:row.ID,action:"goUp",index:row.SN},
				function(data){
					if(data.success){
						grid.bootstrapTable("refresh");
					}else{
						webUtils.alert(data.msg);
					}
				},
				"json"
			);
	}
	
	wiseMen.oa.examSubject.setDown=function(grid,rowIndex){
		var row = grid.bootstrapTable("getRowByIndex", rowIndex);
		$.post(ctx+"/formDataAction/setSort.action",
				{code:"OA_EXAM_SUBJECT",id:row.ID,action:"goDown",index:row.SN},
				function(data){
					if(data.success){
						grid.bootstrapTable("refresh");
					}else{
						webUtils.alert(data.msg);
					}
				},
				"json"
			);
	}
});